﻿using _52_鉴权授权.Models;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace _52_鉴权授权.Controllers
{
    public class HomeController : Controller
    {
       
        // 如果这里是一个数据列表
        // 部分人能看，部分人不能看
        [Authorize(AuthenticationSchemes =CookieAuthenticationDefaults.AuthenticationScheme,Roles = "Admin")] //这里授权仅仅是标记。对标默认授权渠道 加Roles 只有Admin角色可以访问
        public IActionResult Index()
        {
            return View();
        }
        // 要全部满足Roles 就可以访问
        [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Admin")]
        [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Techer")] //这里授权仅仅是标记。对标默认授权渠道 加Roles 只有Admin角色可以访问
        public IActionResult Index1()
        {
            return View();
        }
        // 只要满足Roles里的一个角色 就可以访问
        [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Admin,Techer")]
        public IActionResult Index2()
        {
            return View();
        }
        // 授权策略 再Program.cs
        [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme,Policy = "rolePolicy")]
        public IActionResult Index3()
        {
            return View();
        }
        // 请求来了以后，希望拿到数据去和数据库对比下，通过才调用这个方法
        [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Policy = "rolePolicy")]
        public IActionResult Index4()
        {
            return View();
        }
        public IActionResult NoAuthority()
        {
            return View();
        }
    }
}